#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年4月17日

@author: Administrator
'''

from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models

from common.models import TimeModel

class Like(TimeModel):
    """
    """
    user = models.ForeignKey(User, verbose_name=u'用户')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(db_index=True)
    object = generic.GenericForeignKey('content_type', 'object_id')

    class Meta:
        app_label = 'like'
        verbose_name = u'赞(喜欢)'
        verbose_name_plural = u'赞(喜欢)'
        unique_together = ("user", "content_type", 'object_id')

    def __unicode__(self):
        return u'%s [%s]' % (self.object, self.user.first_name)
